package calendar.messages;

import calendar.Event;
import calendar.User;
import edu.gmu.middleware.Message;
import edu.gmu.streams.BlockInputStream;
import edu.gmu.streams.BlockOutputStream;
import java.io.IOException;

/* this class represents a single user */
import java.util.ArrayList;
public class ScheduleRequest implements Message
{
  public ArrayList users;
  public Event newEvent;
  public Event oldEvent;
  public boolean addToThis;
  
  public ScheduleRequest()
  {
    
  }

  public void marshal(BlockOutputStream stream) throws IOException
  {
    stream.writeInt( this.users.size() );
      for (int i = 0; i < users.size(); i++)
      {
          User user = (User)users.get(i);
          user.marshal(stream);
      }
    stream.writeBoolean( this.newEvent != null );
    if( this.newEvent != null ) this.newEvent.marshal(stream);
    
    stream.writeBoolean( this.oldEvent != null );
    if( this.oldEvent != null ) this.oldEvent.marshal(stream);
    
    stream.writeBoolean(addToThis);
  }
  public void unmarshal(BlockInputStream stream) throws IOException
  {
    int size = stream.readInt();
    this.users = new ArrayList();
      for (int i = 0; i < size; i++)
      {
          User user = new User();
          user.unmarshal(stream);
          this.users.add(user);
      }
    
    boolean isNewEvent = stream.readBoolean();
    if( isNewEvent )
    {
        this.newEvent = new Event();
        this.newEvent.unmarshal(stream);
    }
    
    boolean isOldEvent = stream.readBoolean();
    if( isOldEvent )
    {
        this.oldEvent = new Event();
        this.oldEvent.unmarshal(stream);
    }
    
    this.addToThis = stream.readBoolean();
  }
}
